Setting up Plots

As mentioned above, gnuplot is capable of plotting to many different types of display and file types. Most of the time, gnuplot can correctly identify the display you are using. though this may fail, especially if you are using gnuplot over some kind of remote link. In addition, if you want the plot to be stored in a file for later use, you need to redirect the output of gnuplot. The need to set the right kind of terminal is so common there is a special function to do it — setterm. For more details, see the description in Section [*]. If you don't know exactly which terminal you should be using, try experimenting with gnuplot in interactive mode, especially with the set terminal command, which lists all the available terminal modes. The need to redirect output is less common, though it may occur if you want to import your plots into another package, which requires you to dump the plot to a file. The gnuplot command for this is set output "filename". To do this in , you use the plot command, which passes its string arguments directly to gnuplot. Here is an example of setting up gnuplot to produce graphs in LATEX picture format, and send the output to a file called myfile:
> setterm("latex");
> plot("set output \"myfile\" ");
Note the use of the escaped quotes — quotes are required by gnuplot to delimit the name of the file, however would treat plain quotes as the end of the string. Use of the escape sequence allows a string to have quotes imbedded in it. Setting the output to a file and the terminal type to produce PostScript, and then resetting it to the default setting, is another of the more common things you need to do. In fact there is a function intended for just this, called phrd. For more details on this function, consult Section [*]. In essence, you just supply the process number of the plot you want to dump to a file, and produces a file called rlab-tmp-hrdf.n, where n is the process number. You should be careful not to over-write one plot with the next. In addition, it is possible to send the output of gnuplot to another process. This is done by making the first character of the filename | (pipe symbol), and then directly following it by the name of the program you want to send the output to. The most important use of this is that it allows you to print graphs directly from . Here is an example, for a PostScript printer called imogen :
> setterm("postscript");
> plot("set output \"|lpr -Pimogen\" ");
Note that PostScript is not the only printer format that gnuplot can produce. Most common printers are either supported directly, or can be configured to emulate a printer that is supported. Another thing to note is that some terminal types (generally those for printers) take extra options that specify which mode of the terminal should be used. As mentioned above, a complete list of all terminal types (output formats), and the options they take, can be found by invoking gnuplot at the command line, then using the set terminal command.